package iot.disruptor;

import org.springframework.beans.BeanUtils;

/**
 * Created by dave on 18-8-11 下午10:33.
 */
public interface EventData<T> {

    @SuppressWarnings("unchecked")
    default T duplicate() {
        T instance;
        try {
            instance = (T) this.getClass().newInstance();
        } catch (IllegalAccessException | InstantiationException e) {
            throw new RuntimeException(e);
        }
        copyTo(instance);
        return instance;
    }

    default void copyTo(T event) {
        BeanUtils.copyProperties(this, event);
    }
}
